package com.wzy.oa_sys.controller.attendance;


import com.wzy.oa_sys.model.request.attendance.AttendanceReq;
import com.wzy.oa_sys.model.request.attendance.StandardReq;
import com.wzy.oa_sys.model.response.attendance.AttendanceResp;
import com.wzy.oa_sys.model.response.attendance.VacationResp;
import com.wzy.oa_sys.service.attendance.AttendanceService;
import com.wzy.oa_sys.service.attendance.VacationService;
import com.wzy.oa_sys.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 考勤管理
 */
@RestController
@RequestMapping("/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;
    @Autowired
    private JwtUtil jwtUtil;

    @GetMapping("/list")
    public List<AttendanceResp> getVacationList(HttpServletRequest request) {
        return attendanceService.getAttendanceList(request);
    }

    @PostMapping("/addAttendance")
    public void addAttendance(@RequestBody AttendanceReq attendanceReq, HttpServletRequest request){
        long userId = jwtUtil.extractUserId(request);
        System.out.println("打卡人"+userId);
        attendanceReq.setName(userId);
        System.out.println("考勤："+attendanceReq.toString());
        attendanceService.addAttendance(attendanceReq);
    }


    @GetMapping("/getTodayVacationList")
    public List<AttendanceResp> getTodayVacationList(HttpServletRequest request) {
        Long userId = jwtUtil.extractUserId(request);
        return attendanceService.getTodayVacationList(userId);
    }

}
